%2multibyte Version: 5.50.0.2953 CodePage: 1252

\documentclass[11pt]{article}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{amsfonts}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{harvard}
\usepackage{tabularx}
\usepackage{geometry}
\usepackage{rotating}
\usepackage[title]{appendix}
\usepackage{fancyhdr}
\usepackage[onehalfspacing]{setspace}
\usepackage{hyphenat}
\usepackage{scalefnt}

\setcounter{MaxMatrixCols}{10}
%TCIDATA{OutputFilter=LATEX.DLL}
%TCIDATA{Version=5.50.0.2953}
%TCIDATA{Codepage=1252}
%TCIDATA{<META NAME="SaveForMode" CONTENT="2">}
%TCIDATA{BibliographyScheme=BibTeX}
%TCIDATA{Created=Saturday, October 15, 2005 09:23:02}
%TCIDATA{LastRevised=Wednesday, May 01, 2019 10:35:41}
%TCIDATA{<META NAME="GraphicsSave" CONTENT="32">}
%TCIDATA{<META NAME="DocumentShell" CONTENT="Articles\SW\Standard LaTeX Article (Harvard)">}
%TCIDATA{Language=American English}
%TCIDATA{CSTFile=LaTeX article (bright).cst}

\newtheorem{theorem}{Theorem}
\newtheorem{acknowledgement}[theorem]{Acknowledgement}
\newtheorem{algorithm}[theorem]{Algorithm}
\newtheorem{axiom}[theorem]{Axiom}
\newtheorem{case}[theorem]{Case}
\newtheorem{claim}[theorem]{Claim}
\newtheorem{conclusion}[theorem]{Conclusion}
\newtheorem{condition}[theorem]{Condition}
\newtheorem{conjecture}[theorem]{Conjecture}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{criterion}[theorem]{Criterion}
\newtheorem{definition}[theorem]{Definition}
\newtheorem{example}[theorem]{Example}
\newtheorem{exercise}[theorem]{Exercise}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{notation}[theorem]{Notation}
\newtheorem{problem}[theorem]{Problem}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{remark}[theorem]{Remark}
\newtheorem{solution}[theorem]{Solution}
\newtheorem{summary}[theorem]{Summary}
\newenvironment{proof}[1][Proof]{\noindent \textbf{#1.} }{\  \rule{0.5em}{0.5em}}
\input{tcilatex}
\geometry{left=1.00in,right=0.80in,top=1.0in,bottom=1.0in}
\renewcommand{\cite}{\citeasnoun}
\renewcommand{\setthesection}{\Alph{A}}

\begin{document}

\title{A Toolbox for SMM Estimation of DSGE Models Approximated by Extended
Perturbation up to Fifth Order}
\author{Martin M. Andreasen \\
%EndAName
Aarhus University, the Danish Finance Institute, and CREATES}
\maketitle
\tableofcontents

\bigskip \newpage

\section{Introduction}

The purpose of this note is to document a Matlab toolbox for estimating
dynamic stochastic general equilibrium (DSGE) models by the Simulated method
of moments (SMM) using the extended perturbation approximation up to fifth
order. We illustrate the use of the toolbox by estimating on simulated data
a stylized RBC model approximated up to fifth order. The toolbox also
enables the user to evaluate the accuracy of the considered approximation by
computing the Euler equation errors on either a simulated sample path or a
grid. 

The note is structured as follows. Section \ref{RBCmodel} presents the
stylized RBC model. The required knowledge about SMM estimation to
understand and use our toolbox is provided in Section \ref{SMMestimation}.
We formally present our toolbox in Section \ref{theToolbox} by describing
the steps required to carry out a SMM estimation of the RBC model considered.

It is worth noticing that the toolbox is currently only coded up for linear
shocks when using the extended perturbation approximation. However, with an
appropriate extension of the state variables, it is possible to accommodate
nonlinear features such as stochastic volatility, GARCH, etc. as shown in 
\cite{Andreasen_2012RED}. Note also that in this implementation, both lagged
control variables and exogenous states are concentrated out of the
fixed-point problem for the Extended Path. This ensures consistency between
the states and the controls and it should also reduce the computational
burden.

\bigskip

\section{A Stylized RBC Model\label{RBCmodel}}

This section presents a stylized RBC model similar to the one considered in 
\cite{king_et_al_1999}.

\bigskip

\subsection{Households}

An infinitely lived representative household derives utility from
consumption $C_{t}$ and leisure $L_{t}$. The objective of this household is
to maximize the utility function%
\begin{equation*}
\max ~~\tsum\limits_{j=0}^{\infty }\beta ^{j}d_{t+j}E_{t}\left[ \frac{\left(
C_{t+j}-bC_{t-1+j}\right) ^{1-\eta _{c}}-1}{1-\eta _{c}}+\theta \frac{%
L_{t+j}^{1-\eta _{l}}-1}{1-\eta _{l}}\right] ,
\end{equation*}%
where $E_{t}$ is the conditional expectation operator. This utility function
is described by the structural parameters $\left\{ \beta ,b,\eta _{c},\eta
_{l},\theta \right\} $ where $\beta <1$ is a discount factor. The variable $%
d_{t}$ is a preference shock which evolves as%
\begin{equation*}
\log d_{t+1}=\rho _{d}\log d_{t}+\sigma _{d}\epsilon _{d,t+1}
\end{equation*}%
with $\epsilon _{d,t+1}\sim \mathcal{NID}\left( 0,1\right) $ and $\left\vert
\rho _{d}\right\vert <1$. The parameter $b\in \left[ 0,1\right] $ allows for
internal consumption habits if $b>0$. The household's time endowment is
normalized to one and is allocated to leisure and hours worked $N_{t}$, i.e.%
\begin{equation*}
N_{t}+L_{t}=1.
\end{equation*}%
The capital stock $K_{t}$ is assumed to be owned by the household who also
conduct investments $I_{t}$. The law of motion for capital is given by 
\begin{equation*}
K_{t+1}=\left( 1-\delta \right) K_{t}+I_{t},
\end{equation*}%
where $K_{t}$ is the capital level at the beginning of period $t$ and $%
\delta $ controlling depreciations.\footnote{%
Note that capital is predetermined in period $t$ (i.e. it was set in period $%
t-1$) and some therefore find it more natural to use the notation $%
K_{t}=\left( 1-\delta \right) K_{t-1}+I_{t}$, where $K_{t}$ is the capital
level at the end of period $t$. This alternative notation is used in Dynare
and may also be adopted in this toolbox.}

To derive the budget constraint for the household, let $W_{t}$ denote the
real wage in period $t$ and let $R_{t}^{k}$ refer to the real rental rate of
capital in period $t$. The representative household also receives real
dividends $\Pi _{t}$ from firms, implying that its total real income in
period $t$ is given by%
\begin{equation*}
\text{income}_{t}\text{=}W_{t}N_{t}+R_{t}^{k}K_{t}+\Pi _{t}.
\end{equation*}%
This income is used for either consumption or investments, meaning that the
budget constraint reads%
\begin{equation*}
C_{t}+I_{t}\leq W_{t}N_{t}+R_{t}^{k}K_{t}+\Pi _{t}.
\end{equation*}%
Thus the optimization problem faced by the representative household is%
\begin{equation*}
\max_{\left( C_{t+j},N_{t+j},K_{t+1+j},I_{t+j}\right) _{j=0}^{\infty
}}~~\tsum\limits_{j=0}^{\infty }\beta ^{j}d_{t+j}E_{t}\left[ \frac{\left(
C_{t+j}-bC_{t-1+j}\right) ^{1-\eta _{c}}-1}{1-\eta _{c}}+\theta \frac{\left(
1-N_{t+j}\right) ^{1-\eta _{l}}-1}{1-\eta _{l}}\right] 
\end{equation*}%
subject to 
\begin{equation*}
C_{t}+I_{t}\leq W_{t}N_{t}+R_{t}^{k}K_{t}+\Pi _{t}
\end{equation*}%
\begin{equation*}
K_{t+1}=\left( 1-\delta \right) K_{t}+I_{t}
\end{equation*}%
(and a no-Ponzi-game condition which we abstract from). The solution is a
set of contingency plans for $C_{t},N_{t},K_{t+1}$, and $I_{t}$ as a
function of the state variables. It is easy to show that the optimization
problem implies the following first-order conditions:%
\begin{equation*}
\frac{\partial \tciLaplace }{\partial C_{t}}:d_{t}\left(
C_{t}-bC_{t-1}\right) ^{-\eta _{c}}-\beta bE_{t}\left[ d_{t+1}\left(
C_{t+1}-bC_{t}\right) ^{-\eta _{c}}\right] =\lambda _{t}
\end{equation*}%
\begin{equation*}
\frac{\partial \tciLaplace }{\partial N_{t}}:\theta d_{t}\left(
1-N_{t}\right) ^{-\eta _{l}}=\lambda _{t}W_{t}
\end{equation*}%
\begin{equation*}
\frac{\partial \tciLaplace }{\partial K_{t+1}}:\lambda _{t}=E_{t}\left[
\beta \lambda _{t+1}\left( R_{t+1}^{k}+\left( 1-\delta \right) \right) %
\right] 
\end{equation*}%
where $\lambda _{t}$ is the lagrange multiplier on the budget constraint.

\bigskip

\subsection{Firms}

Production $Y_{t}$ is carried out using a Cobb-Douglas production function%
\begin{equation*}
Y_{t}=A_{t}K_{t}^{1-\alpha }N_{t}^{\alpha },
\end{equation*}%
where $A_{t}$ refers to productivity shocks that evolves as%
\begin{equation*}
\log A_{t+1}=\rho _{A}\log A_{t}+\sigma _{A}\epsilon _{A,t+1}
\end{equation*}%
with $\epsilon _{A,t+1}\sim \mathcal{NID}\left( 0,1\right) $ and $\left\vert
\rho _{A}\right\vert <1$. Firm profit is given by%
\begin{equation*}
\Pi _{t}=A_{t}K_{t}^{1-\alpha }N_{t}^{\alpha }-W_{t}N_{t}-R_{t}^{k}K_{t},
\end{equation*}%
and when optimized across capital and hours worked we get the standard
first-order conditions:%
\begin{equation*}
\frac{\partial \Pi _{t}}{\partial K_{t}}:A_{t}\left( 1-\alpha \right)
K_{t}^{-\alpha }N_{t}^{\alpha }=R_{t}^{k}
\end{equation*}%
\begin{equation*}
\frac{\partial \Pi _{t}}{\partial N_{t}}:A_{t}\alpha K_{t}^{1-\alpha
}N_{t}^{\alpha -1}=W_{t}.
\end{equation*}

\bigskip

\subsection{Market clearing and Model Summary}

Equilibrium in the goods market implies $C_{t}+I_{t}=Y_{t}$, which is
satisfied via the budget constraint because $\Pi _{t}=0$ and $%
W_{t}N_{t}+R_{t}^{k}K_{t}=Y_{t}$. Hence, our economy can be condensely
expressed as:%
\begin{equation*}
\begin{tabular}{l|l}
\hline
1 & $d_{t}\left( C_{t}-bC_{t-1}\right) ^{-\eta _{c}}-\beta bE_{t}\left[
d_{t+1}\left( C_{t+1}-bC_{t}\right) ^{-\eta _{c}}\right] =\lambda _{t}$ \\ 
2 & $\theta d_{t}\left( 1-N_{t}\right) ^{-\eta _{l}}=\lambda _{t}W_{t}$ \\ 
3 & $\lambda _{t}=E_{t}\left[ \beta \lambda _{t+1}\left( R_{t+1}^{k}+\left(
1-\delta \right) \right) \right] $ \\ 
4 & $A_{t}\left( 1-\alpha \right) K_{t}^{-\alpha }N_{t}^{\alpha }=R_{t}^{k}$
\\ 
5 & $A_{t}\alpha K_{t}^{1-\alpha }N_{t}^{\alpha -1}=W_{t}$ \\ 
6 & $C_{t}+I_{t}=Y_{t}$ \\ 
7 & $Y_{t}=A_{t}K_{t}^{1-\alpha }N_{t}^{\alpha }$ \\ 
8 & $K_{t+1}=\left( 1-\delta \right) K_{t}+I_{t}$ \\ 
9 & $\left( C_{t-1}\right) _{t+1}=C_{t}$ \\ 
10 & $\log A_{t+1}=\rho _{A}\log A_{t}+\sigma _{A}\epsilon _{A,t+1}$ \\ 
11 & $\log d_{t+1}=\rho _{d}\log d_{t}+\sigma _{d}\epsilon _{d,t+1}$ \\ 
\hline
\end{tabular}%
\end{equation*}%
This economy has four state variables $\left(
K_{t},C_{t-1},A_{t},d_{t}\right) $ and seven control variables $\left(
C_{t},\lambda _{t},W_{t},R_{t}^{k},N_{t},I_{t},Y_{t}\right) $. Note that we
in Eq 9 introduce a so-called link equation, that relates lagged consumption
next period to the present consumption, i.e. $\left( C_{t-1}\right)
_{t+1}=C_{t}$.

\bigskip

\subsection{The Steady State}

The steady state solution is defined as the point where there are no shocks
hitting the economy and all dynamics have played out, implying that we can
replace all time-subscript by $ss$ and solve for all variables as a function
of the structural parameters. From Eq 10 and Eq 11 we have $A_{ss}=1$ and $%
d_{ss}=1$. Eq 3 implies $\lambda _{ss}=\beta \lambda _{ss}\left(
R_{ss}^{k}+\left( 1-\delta \right) \right) $, and therefore 
\begin{equation*}
R_{ss}^{k}=\frac{1}{\beta }-\left( 1-\delta \right) .
\end{equation*}%
From Eq 4 we have $A_{ss}\left( 1-\alpha \right) K_{ss}^{-\alpha
}N_{ss}^{\alpha }=R_{ss}^{k}$, which is equivalent to 
\begin{equation*}
\frac{K_{ss}}{N_{ss}}=\left( \frac{R_{ss}^{k}}{A_{ss}\left( 1-\alpha \right) 
}\right) ^{-1/\alpha }.
\end{equation*}%
From Eq 5 we directly get%
\begin{equation*}
W_{ss}=A_{ss}\alpha \left( \frac{K_{ss}}{N_{ss}}\right) ^{1-\alpha }.
\end{equation*}%
The law of motion for capital in Eq 8 implies%
\begin{equation*}
\frac{I_{ss}}{N_{ss}}=\delta \frac{K_{ss}}{N_{ss}}.
\end{equation*}%
The production function in Eq 7 gives%
\begin{equation*}
\frac{Y_{ss}}{N_{ss}}=A_{ss}\left( \frac{K_{ss}}{N_{ss}}\right) ^{1-\alpha }.
\end{equation*}%
From Eq 6 we have%
\begin{equation*}
\frac{C_{ss}}{N_{ss}}=\frac{Y_{ss}}{N_{ss}}-\frac{I_{ss}}{N_{ss}}.
\end{equation*}%
Combining Eq 1 and 2, we have%
\begin{equation*}
\theta \left( 1-N_{ss}\right) ^{-\eta _{l}}\frac{1}{N_{ss}^{-\eta _{c}}}=%
\frac{\left( 1-\beta b\right) \left( C_{ss}-bC_{ss}\right) ^{-\eta _{c}}}{%
N_{ss}^{-\eta _{c}}}W_{ss}
\end{equation*}%
$\Updownarrow $%
\begin{equation*}
\theta \left( 1-N_{ss}\right) ^{-\eta _{l}}N_{ss}^{\eta _{c}}=\left( \frac{%
C_{ss}}{N_{ss}}\right) ^{-\eta _{c}}\left( 1-\beta b\right) \left(
1-b\right) ^{-\eta _{c}}W_{ss}.
\end{equation*}%
We can assume that $N_{ss}$ is known (for instance $N_{ss}=1/3$) and solve
for the value of $\theta $. Alternatively, and as done in the current
implementation, condition on a value of $\theta $ and solve for $N_{ss}$ by
a numerical fixed-point algorithm. If $\eta ^{l}=\eta ^{c}=1$ (i.e. log-log
preferences) then we have the following closed-form solution%
\begin{equation*}
\theta \frac{N_{ss}}{1-N_{ss}}=\left( \frac{C_{ss}}{N_{ss}}\right)
^{-1}\left( 1-\beta b\right) \left( 1-b\right) ^{-1}W_{ss}
\end{equation*}%
$\Updownarrow $%
\begin{equation*}
N_{ss}=\left( 1-N_{ss}\right) \left( \frac{C_{ss}}{N_{ss}}\right) ^{-1}\frac{%
\left( 1-\beta b\right) W_{ss}}{\theta \left( 1-b\right) }
\end{equation*}%
$\Updownarrow $%
\begin{equation*}
N_{ss}=\frac{\left( \frac{C_{ss}}{N_{ss}}\right) ^{-1}\frac{\left( 1-\beta
b\right) W_{ss}}{\theta \left( 1-b\right) }}{1+\left( \frac{C_{ss}}{N_{ss}}%
\right) ^{-1}\frac{\left( 1-\beta b\right) W_{ss}}{\theta \left( 1-b\right) }%
}.
\end{equation*}%
Given a value of $N_{ss}$, we trivially have all the desired quantities
using the previous expressions for $\frac{C_{ss}}{N_{ss}}$, $\frac{I_{ss}}{%
N_{ss}}$, $\frac{K_{ss}}{N_{ss}}$, and $\frac{Y_{ss}}{N_{ss}}$.

\bigskip

\section{Theory on SMM Estimation\label{SMMestimation}}

This section describes how our RBC model can be estimated by SMM. We proceed
by introducing the SMM estimator in Section \ref{SMMnotation}. The
asymptotic distribution of this estimator is given in Section \ref{asympSMM}%
, and we finally discuss the considered moments for our SMM estimator in
Section \ref{momentsSMM}. For additional introduction to SMM, see for
instance \cite{RugeMurcia_2012}.

\bigskip

\subsection{The SMM estimator\label{SMMnotation}}

To present the SMM estimator, let $\mathbf{y}_{t}$ with dimension $%
n_{y}\times 1$ contain our observed variables in period $t$, with the entire
sample denoted by $\mathbf{y}_{1:T}=\left\{ \mathbf{y}_{1},\mathbf{y}%
_{2},...,\mathbf{y}_{T}\right\} $. The structural parameters in our DSGE
model is denoted by $\mathbf{\theta }$ with dimension $n_{\theta }\times 1$.
The objective in SMM is to estimate $\mathbf{\theta }$ using a set of moment
conditions. We focus on first and second unconditional moments as typically
done when estimating DSGE\ models. More formally, consider $n_{m}$
unconditional moments $E^{S}\left[ \mathbf{m}\left( \mathbf{\theta }\right) %
\right] =\frac{1}{\tau T}\sum_{s=1}^{\tau T}\mathbf{m}\left( \mathbf{\theta }%
,\mathbf{y}_{s}\right) $ from our DSGE model, which we compute based on a
simulated sample path of $\tau T$ observations. Here, $T$ is the length of
our empirical sample and $\tau $ is an integer controlling the length of the
simulated sample path. We next define the function $\mathbf{h}^{S}\left( 
\mathbf{\theta ,y}_{t}\right) \equiv \mathbf{m}\left( \mathbf{y}_{t}\right)
-E^{S}\left[ \mathbf{m}\left( \mathbf{\theta }\right) \right] $. Let $%
\mathbf{\theta }_{o}$ denote the true value of $\mathbf{\theta }$, which
implies $E^{S}\left[ \mathbf{h}\left( \mathbf{\theta }_{o}\mathbf{,y}%
_{t}\right) \right] =\mathbf{0}$\textbf{.} The estimation applies the sample
analogue 
\begin{equation*}
\mathbf{g}^{S}\left( \mathbf{\theta ,y}_{1:T}\right) =\frac{1}{T}%
\sum_{t=1}^{T}\mathbf{h}^{S}\left( \mathbf{\theta ,y}_{t}\right) 
\end{equation*}%
as a substitute for the expectation operator, and the SMM estimator is then
given by (see \cite{Duffie&Singleton_1993})%
\begin{equation}
\mathbf{\theta }_{SMM}=\underset{\mathbf{\theta \in \Theta }}{\arg \min }~~%
\mathbf{g}^{S}\left( \mathbf{\theta ,y}_{1:T}\right) ^{\prime }\mathbf{W}_{T}%
\mathbf{g}^{S}\left( \mathbf{\theta ,y}_{1:T}\right) .  \label{SMM1}
\end{equation}%
Here, $\mathbf{W}_{T}$ is an $n_{m}\times n_{m}$ positive definite weighting
matrix that may depend on $\mathbf{y}_{1:T}$. Note that $n_{m}\geq n_{\theta
}$ is a necessary but not a sufficient condition for identification of $%
\mathbf{\theta }$\textbf{. }A weighting matrix $\mathbf{W}_{T}$ is thus
required to make SMM operational. One commonly used approach is to determine 
$\mathbf{W}_{T}$ from $\mathbf{y}_{1:T}$. This can be done by using the
Newey-West estimator, i.e. 
\begin{equation*}
\mathbf{\hat{S}=}\hat{\Gamma}_{0}+\sum_{\nu =1}^{q}\left( 1-\frac{\nu }{q+1}%
\right) \left( \hat{\Gamma}_{\nu }+\hat{\Gamma}_{\nu }^{\prime }\right) 
\end{equation*}%
where 
\begin{eqnarray}
\hat{\Gamma}_{\nu } &=&\frac{1}{T}\sum_{t=1}^{T}\mathbf{h}^{S}\left( \mathbf{%
\hat{\theta}}^{\left( 1\right) }\mathbf{,y}_{t}\right) \mathbf{h}^{S}\left( 
\mathbf{\hat{\theta}}^{\left( 1\right) }\mathbf{,y}_{t-\nu }\right) ^{\prime
}  \label{SMM2} \\
&=&\frac{1}{T}\sum_{t=1}^{T}\left( \mathbf{m}\left( \mathbf{y}_{t}\right)
-E^{S}\left[ \mathbf{m}\left( \mathbf{\hat{\theta}}^{\left( 1\right)
}\right) \right] \right) \left( \mathbf{m}\left( \mathbf{y}_{t-\nu }\right)
-E^{S}\left[ \mathbf{m}\left( \mathbf{\hat{\theta}}^{\left( 1\right)
}\right) \right] \right) ^{\prime }.  \notag
\end{eqnarray}%
Here, $\mathbf{\hat{\theta}}^{\left( 1\right) }$ denotes a preliminary first
step estimate of $\mathbf{\theta }$ using (\ref{SMM1}) with $\mathbf{W}_{T}=%
\mathbf{I}$, whereas the optimal weighting matrix is given by $\mathbf{\hat{S%
}}^{-1}$. Instead of using $\mathbf{W}_{T}=\mathbf{I}$ in the first step,
another possibility is to observe that for the true value of $\mathbf{\theta 
}$ we have $E\left[ \mathbf{g}^{S}\left( \mathbf{\theta }_{0}\mathbf{,y}%
_{1:T}\right) \right] =\mathbf{0}$, implying%
\begin{equation*}
E\left[ \frac{1}{T}\sum_{t=1}^{T}\mathbf{m}\left( \mathbf{y}_{t}\right) %
\right] =E^{S}\left[ \mathbf{m}\left( \mathbf{\theta }_{o}\right) \right] .
\end{equation*}%
Hence, if we let $\mathbf{m}_{T}\mathbf{\equiv }\frac{1}{T}\sum_{t=1}^{T}%
\mathbf{m}\left( \mathbf{y}_{t}\right) $, we can use the sample mean of the
moments to estimate $E^{S}\left[ \mathbf{m}\left( \mathbf{\theta }%
_{o}\right) \right] $ instead of $E\left[ \mathbf{m}\left( \mathbf{\hat{%
\theta}}^{\left( 1\right) }\right) \right] $. This leads to the alternative
estimator%
\begin{equation*}
\hat{\Gamma}_{\nu ,mean}=\frac{1}{T}\sum_{t=1}^{T}\left( \mathbf{m}\left( 
\mathbf{y}_{t}\right) -\mathbf{m}_{T}\right) \left( \mathbf{m}\left( \mathbf{%
y}_{t}\right) -\mathbf{m}_{T}\right) ^{\prime },
\end{equation*}%
which does not require a preliminary estimate of $\mathbf{\theta }$. Hence,
the \QTR{frametitle}{weighting matrix may be obtain using}%
\begin{equation*}
\mathbf{\hat{S}}_{mean}\mathbf{=}\hat{\Gamma}_{0,mean}+\sum_{\nu
=1}^{q}\left( 1-\frac{\nu }{q+1}\right) \left( \hat{\Gamma}_{\nu ,mean}+\hat{%
\Gamma}_{\nu ,mean}^{\prime }\right) .
\end{equation*}%
Given $\mathbf{\hat{S}}_{mean}$, we may either let $\mathbf{W}_{T}=\left( 
\mathbf{\hat{S}}_{mean}\right) ^{-1}$ or only use the diagonal elements of $%
\mathbf{\hat{S}}_{mean}$ and let $\mathbf{W}_{T}=\left( diag\left( \mathbf{%
\hat{S}}_{mean}\right) \right) ^{-1}$. We prefer the latter option as it
implies that all moments in the estimation are scaled according to how
precise they are estimated in the sample.

\bigskip

To summarize, the estimation procedure implemented in our toolbox by SMM is
as follows:

\begin{enumerate}
\item Step: Let $\mathbf{W}_{T}=\left( diag\left( \mathbf{\hat{S}}%
_{mean}\right) \right) ^{-1}$ and obtain $\mathbf{\hat{\theta}}^{\left(
1\right) }$ from (\ref{SMM1}).

\item Step: Use $\mathbf{\hat{\theta}}^{\left( 1\right) }$ to compute $%
\mathbf{\hat{W}}_{T}^{\left( 1\right) }=\mathbf{\hat{S}}^{-1}$, and obtain $%
\mathbf{\hat{\theta}}^{\left( 2\right) }$ from (\ref{SMM1})
\end{enumerate}

\bigskip

\subsection{Asymptotic Distribution of the SMM Estimator\label{asympSMM}}

Given standard regularity conditions, \cite{Duffie&Singleton_1993} show that
the SMM estimator is asymptotically normally distributed, i.e.%
\begin{equation*}
\sqrt{T}\left( \mathbf{\hat{\theta}}-\mathbf{\theta }_{o}\right) \overset{d}{%
\longrightarrow }\mathcal{N}\left( \mathbf{0,}\left( 1+\frac{1}{\tau }%
\right) \mathbf{M}_{o}\mathbf{S}_{o}\mathbf{M}_{o}^{\prime }\right) ,
\end{equation*}%
where 
\begin{equation*}
\mathbf{M}_{o}=\left( \mathbf{D}_{o}^{\prime }\mathbf{W}_{T}\mathbf{D}%
_{o}\right) ^{-1}\mathbf{D}_{o}^{\prime }\mathbf{W}_{T}
\end{equation*}%
and%
\begin{equation*}
\mathbf{D}_{o}\mathbf{=}\left. \frac{\partial \mathbf{g}^{S}\left( \mathbf{%
\theta ,y}_{1:T}\right) }{\partial \mathbf{\theta }^{\prime }}\right\vert _{%
\mathbf{\theta =\theta }_{o}}.
\end{equation*}%
We estimate these matrices by replacing $\mathbf{\theta }_{o}$ by $\mathbf{%
\hat{\theta}}$. If we use the optimal weighting matrix $\mathbf{W}_{T}=%
\mathbf{S}_{o}^{-1}$, the expression for the asymptotic variance simplifies
to%
\begin{equation*}
\sqrt{T}\left( \mathbf{\hat{\theta}}-\mathbf{\theta }_{o}\right) \overset{d}{%
\longrightarrow }\mathcal{N}\left( \mathbf{0,}\left( 1+\frac{1}{\tau }%
\right) \left( \mathbf{D}_{o}^{\prime }\mathbf{S}_{o}^{-1}\mathbf{D}%
_{o}\right) ^{-1}\right) \text{.}
\end{equation*}%
In this case a model specification test is given by (see \cite%
{RugeMurcia_2012})%
\begin{equation*}
J=T\left( 1+\frac{1}{\tau }\right) \mathbf{g}\left( \mathbf{\hat{\theta},y}%
_{1:T}\right) ^{\prime }\mathbf{\hat{S}}^{-1}\mathbf{g}\left( \mathbf{\hat{%
\theta},y}_{1:T}\right) \overset{d}{\longrightarrow }\chi _{n_{m}-n_{\theta
}}^{2}.
\end{equation*}

\bigskip

\subsection{Moments Applied for the SMM Estimator\label{momentsSMM}}

We allow three types of unconditional moments to be considered for the SMM
estimation:

\begin{itemize}
\item Sample means, i.e. $\mathbf{m}_{1}\left( \mathbf{y}_{t}\right) =%
\mathbf{y}_{t}$

\item Contemporaneous covariances, i.e. $\mathbf{m}_{2}\left( \mathbf{y}%
_{t}\right) =vech\left( \mathbf{y}_{t}\mathbf{y}_{t}^{\prime }\right) $

\item The own auto-covariances, i.e. $\mathbf{m}_{3}\left( \mathbf{y}%
_{t}\right) =\left\{ y_{i,t}y_{i,t-k}\right\} _{i=1}^{n_{y}}$ for various
values of $k$
\end{itemize}

Hence, the total set of moments considered for the estimation is given by%
\begin{equation*}
\mathbf{m}\left( \mathbf{y}_{t}\right) \mathbf{\equiv }\left[ 
\begin{array}{c}
\mathbf{m}_{1}\left( \mathbf{y}_{t}\right)  \\ 
\mathbf{m}_{2}\left( \mathbf{y}_{t}\right)  \\ 
\mathbf{m}_{3}\left( \mathbf{y}_{t}\right) 
\end{array}%
\right] .
\end{equation*}%
Finally, the user can then freely decide which of the moments in $\mathbf{m}%
\left( \mathbf{y}_{t}\right) $ that are included in the estimation.

\section{Implementing SMM Estimation in the Toolbox\label{theToolbox}}

This section explains the steps required to carry out a SMM estimation of a
DSGE model when approximated up to fifth order by the extended perturbation
method. The most demanding aspect for the user relates to constructing two
model specific m-files containing i) the model equations and ii) the steady
state solution. The requirements we impose on these two files are mainly due
to our desire to concentrate out lagged control variables and the exogenous
states when solving for the Extended Path. 

We proceed as follows. Section \ref{overviewToolbox} provides a brief
overview of the toolbox. Section \ref{ModelEquations} outlines how the model
equations should be coded up, and Section \ref{SteadyState} provide guidance
on how to implement the steady state solution. The case with non-standard
transformations of any variable in the model is discussed in Section \ref%
{untransformXandY}. We then show in Section \ref{NumDerivatives} how to
automatically generate functions that efficiently compute the numerical
derivatives of the model up to fifth as needed for the perturbation
approximation, two additional files needed to run the Extended Path, and
finally files for evaluating the Euler equation errors. Section \ref{runSMM}
illustrates how to estimate the stylized RBC model by SMM, and Section \ref%
{accuracy} shows how to evaluate accuracy.

\bigskip

\subsection{Overview of the Toolbox\label{overviewToolbox}}

The toolbox has the following folders:

\begin{itemize}
\item \textbf{AccuracyEuler:} Codes needed for computing Euler equation
errors.

\item \textbf{DisplayModelDeriv}: This folder contains a set of general
m-files that is used to generate functions to compute the DSGE model at the
steady state, compute the Extended Path, and compute the Euler equation
errors. These files are called by the executable scripts
"createFiles\_Derivatives\_model.m" and
"createFiles\_ExtendedPathAndAccuracy.m".

\item \textbf{Documentation}: The documentation of the toolbox is saved here.

\item \textbf{ExtendedPer}: Codes accompanying the paper by \cite%
{AndreasenKronborg_2018}\ on how to compute the Extended Path efficiently
and hence compute the extended perturbation approximation.

\item \textbf{files:} Contains the required files for using the codes by 
\cite{Levintal_2017} to compute the standard perturbation approximation up
to fifth order.

\item \textbf{ModelSpecification}: The content of this folder is reserved to
the user and should contain the following files:

\begin{itemize}
\item An m-file with the equations of the DSGE model

\item An m-file computing the steady state of the DSGE model
\end{itemize}

The remaining files in this folder will be generated automatically when
running "createFiles\_Derivatives\_model.m" and
"createFiles\_ExtendedPathAndAccuracy.m".

\item \textbf{Perturbation\_Levintal}: This folder contains the code
accompanying \cite{Levintal_2017}.

\item \textbf{SMMtoolbox}: This folder contains a set of general m-files
needed to carry out the SMM estimation of a DSGE model solved by the
extended perturbation method and standard perturbation (with pruning) up to
fifth order. The latter is included as a useful benchmark or to obtain good
starting values for an estimation based on extended perturbation.
\end{itemize}

\bigskip

In addition to these folders, the toolbox contains five executable scripts:

\begin{itemize}
\item "createFiles\_ExtendedPathAndAccuracy.m" uses the m-file for the DSGE
model and its steady state solution to automatically generate
"DSGEforesight\_N.m", "getModelDeriv\_EP.m", "EulerEqError.m", and
"EulerEqErrorPruning.m"

\item "createFiles\_Derivatives\_model.m" computes the required derivatives
for a standard fifth order perturbation approximation.

\item "Run\_accuracyEuler.m" a script to evaluate the Euler equation errors

\item "Run\_solveAndSimulateModel.m" a script to simulate a sample path from
the DSGE model by extended perturbation.

\item "SunGMM.m" is the main script for carrying out the SMM estimation.
\end{itemize}

\bigskip

\subsection{Implementing The Model Equations\label{ModelEquations}}

When implementing the model equations describing the DSGE model, we adopt
the notation and framework of \cite{SGU_2004}. That is, we use the symbolic
toolbox in Matlab to set up a function that reports the model equations
along with the state and control vectors. Our implementation of the RBC
model is available in "RBCmodel.m" which appears in the folder
"ModelSpecification".

The first section of the file "RBCmodel.m" is given below:%
%TCIMACRO{%
%\FRAME{dtbpFX}{5.39in}{2.5993in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.39in;height 2.5993in;depth 0pt;original-width 6.2745in;original-height 3.0087in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSENB00.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=3.0087in, natwidth=6.2745in, height=2.5993in, width=5.39in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSENB00__1.pdf}}%
\end{center}
%EndExpansion
We start by using the Matlab option "syms" to define the structural
parameters of the model as symbolic objects. All these symbolic variables
are then stored in "symparams." Then we define the state variables as
symbolic objects and then the control variables. When defining these
variables, we adopt the following notation (explained using a few examples)

\begin{itemize}
\item $K_{t}$ is coded as $k\_cu$ where "\_cu" is an abbreviation for
"current"

\item $K_{t+1}$ is coded as $k\_cup$ where "\_cup" is an abbreviation for
"current, plus one"

\item $C_{t-1}$ is coded as $c\_ba1$ where "\_ba" is for "back" and 1 refers
to one lag
\end{itemize}

The second section of the file "RBCmodel.m" contains Eq 1 to 8 of our model.
That is%
%TCIMACRO{%
%\FRAME{dtbpFX}{4.4195in}{3.7441in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 4.4195in;height 3.7441in;depth 0pt;original-width 6.2745in;original-height 5.3097in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSF2V03.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=5.3097in, natwidth=6.2745in, height=3.7441in, width=4.4195in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSF2V03__2.pdf}}%
\end{center}
%EndExpansion
and%
%TCIMACRO{%
%\FRAME{dtbpFX}{4.4195in}{3.4968in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 4.4195in;height 3.4968in;depth 0pt;original-width 6.2745in;original-height 4.9562in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSF3A04.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=4.9562in, natwidth=6.2745in, height=3.4968in, width=4.4195in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSF3A04__3.pdf}}%
\end{center}
%EndExpansion

Note that we do not explicitly write the conditional expectation operator,
as the perturbation codes automatically takes the conditional expectation at
time $t$ to all equations of the model. For the Extended Path, it is useful
to also accommodate the case where all the model equations (and hence their
errors) are expressed in unit free terms to make them mutually comparable.
This is done by scaling each of the equilibrium equations such that we equal
0 or 1. For instance, the equation $C_{t}+I_{t}=Y_{t}$ is expressed as $%
C_{t}/Y_{t}+I_{t}/Y_{t}=1$.

\bigskip

The third section in the file "RBCmodel.m" is reserved for link-equations.
Our RBC model has only one link-equation for consumption, i.e.%
%TCIMACRO{%
%\FRAME{dtbpFX}{5.6737in}{0.9567in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.6737in;height 0.9567in;depth 0pt;original-width 6.3741in;original-height 1.0493in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'OGS3WO03.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.0493in, natwidth=6.3741in, height=0.9567in, width=5.6737in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/OGS3WO03__4.pdf}}%
\end{center}
%EndExpansion
Note if we have additional lagged control variables in the model, then they
appear as additional state variables and lead to additional link-equations.
It is important to note that the link equations must appear after the main
equations of the model in order to exploit the fact that we do not
separately need to solve for $C_{t-1}$ in the Extended Path. 

\bigskip

The fourth section in the file "RBCmodel.m" specifies the exogenous shocks
to the model using the representation in Eq 10 and Eq 11, i.e. 
%TCIMACRO{%
%\FRAME{dtbpFX}{5.6737in}{0.9843in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.6737in;height 0.9843in;depth 0pt;original-width 6.2745in;original-height 1.0621in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSF7D05.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.0621in, natwidth=6.2745in, height=0.9843in, width=5.6737in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSF7D05__5.pdf}}%
\end{center}
%EndExpansion
It is important that the equations for the exogenous shocks appear last in
the $\mathbf{f}$-function when computing the certainty equivalent solution
by the Extended Path. Note also that we do not explicitly type in the
structural innovations, i.e. we do not need to write $\sigma _{A}\epsilon
_{A,t+1}$. Note also that the adopted timing convention for the exogenous
shocks differs from the one used in Dynare, where the law of motion for
technology typically would be represented as%
\begin{equation*}
\log A_{t}=\rho _{A}\log A_{t-1}+\sigma _{A}\epsilon _{A,t}.
\end{equation*}%
This is because Dynare considers both $A_{t-1}$ and $\epsilon _{A,t}$ as
state variables. By using the representation in Eq 10, i.e. $\log
A_{t+1}=\rho _{A}\log A_{t}+\sigma _{A}\epsilon _{A,t+1}$, only $A_{t}$
appears as a state variable, which reduces the computational burden when
solving the DSGE model. We finally stack all equations in section 4 and
construct the vector function $\mathbf{f}$.

\bigskip

The final section of the file "RBCmodel.m" defines the state vector 
\begin{equation*}
\mathbf{x}_{t}=\left[ 
\begin{array}{cccc}
K_{t} & C_{t-1} & A_{t} & d_{t}%
\end{array}%
\right] 
\end{equation*}%
and the control vector 
\begin{equation*}
\mathbf{y}_{t}=\left[ 
\begin{array}{ccccccc}
C_{t} & I_{t} & Y_{t} & \lambda _{t} & N_{t} & R_{t}^{k} & W_{t}%
\end{array}%
\right] 
\end{equation*}%
in the following way:%
%TCIMACRO{%
%\FRAME{dtbpFX}{5.6737in}{2.5766in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.6737in;height 2.5766in;depth 0pt;original-width 6.2745in;original-height 2.832in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSFAP06.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=2.832in, natwidth=6.2745in, height=2.5766in, width=5.6737in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSFAP06__6.pdf}}%
\end{center}
%EndExpansion
Note the that $\mathbf{x}_{t}$ is coded as $\mathbf{x}$ and $\mathbf{x}_{t+1}
$ is coded as $\mathbf{xp}$ following the convention introduced by \cite%
{SGU_2004}, and similarly for the control vector. In order to only solve for
the control variables and the \textit{endogenous} states in the Extended
Path, we impose that the state and control vector must be defined as follows:%
\begin{equation}
\underset{nx}{\underbrace{\mathbf{x}_{t}}}=\left[ 
\begin{array}{ccc}
\underset{mx}{\underbrace{\text{endogenous~states}}} & \underset{myx}{%
\underbrace{\text{controls appearing in }\mathbf{x}_{t}}} & \underset{ne}{%
\underbrace{\text{exogenous~states}}}%
\end{array}%
\right]   \label{1}
\end{equation}%
\begin{equation}
\underset{ny}{\underbrace{\mathbf{y}_{t}}}=\left[ 
\begin{array}{cc}
\underset{myx}{\underbrace{\text{controls appearing in }\mathbf{x}_{t}}} & 
\text{remaining controls}%
\end{array}%
\right]   \label{2}
\end{equation}%
Note that the size of the vectors are given below, i.e. $\mathbf{x}_{t}$ has
nx elements and so on. Applying these rules to our RBC model, this explains
why the state vector is defined as $K_{t}$ (the endogenous state variable), $%
C_{t-1}$ (the lagged control variable), and $\left( A_{t},d_{t}\right) $
(the exogenous states). Note also that the order of the variables "controls
appearing in $\mathbf{x}_{t}$" must be the same in $\mathbf{x}_{t}$ and $%
\mathbf{y}_{t}$. This explains why $C_{t}$ appears as the first control
variable in $\mathbf{y}_{t}$.

The final line in the codes above is needed for a log-approximation as it
replaces all elements in $\left[ \mathbf{x}_{t},\mathbf{y}_{t},\mathbf{x}%
_{t+1},\mathbf{y}_{t+1}\right] $ by $\exp \left\{ \left[ \mathbf{x}_{t},%
\mathbf{y}_{t},\mathbf{x}_{t+1},\mathbf{y}_{t+1}\right] \right\} $ in the $%
\mathbf{f}$\textbf{-}function. That is, the $\mathbf{f}$\textbf{-}function
changes from%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7512in}{1.8777in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 1.8777in;depth 0pt;original-width 6.2745in;original-height 1.7261in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSFHM07.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.7261in, natwidth=6.2745in, height=1.8777in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSFHM07__7.pdf}}%
\end{center}
%EndExpansion
to%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7512in}{1.5802in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 1.5802in;depth 0pt;original-width 6.2745in;original-height 1.4488in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSFKQ08.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.4488in, natwidth=6.2745in, height=1.5802in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSFKQ08__8.pdf}}%
\end{center}
%EndExpansion
Effectively, this transformation implies that the perturbation approximation
is carried out for a log-transformation of the state and control variables,
i.e. for 
\begin{equation*}
\mathbf{x}_{t}=\left[ 
\begin{array}{cccc}
\log K_{t} & \log C_{t-1} & \log A_{t} & \log d_{t}%
\end{array}%
\right] 
\end{equation*}%
\begin{equation}
\mathbf{y}_{t}=\left[ 
\begin{array}{ccccccc}
\log C_{t} & \log I_{t} & \log Y_{t} & \log \lambda _{t} & \log N_{t} & \log
R_{t}^{k} & \log W_{t}%
\end{array}%
\right] .  \label{3}
\end{equation}%
However, the package also accommodates the possibility of using a simple
'level' approximation, which in this case corresponds to omitting "f =
subs(f, ...)". Another possibility which is also accommodated is to use a
logistic transformation of a variable. This may be a convenient
transformation to consider if a variable lies within the unit interval. For
instance, for some variable $X_{t}$ in the model, we may let 
\begin{equation*}
X_{t}=\frac{1}{1+e^{-\tilde{X}_{t}}}
\end{equation*}%
and do the approximation in $\tilde{X}_{t}$.

Finally, in "Phi" the user has the opportunity to report the conditional
expectation of the exogenous shocks, which may be used by the codes of \cite%
{Levintal_2017} when computing the standard perturbation approximation.

\bigskip 

We acknowledge that the required ordering of the model equations and the
state and control variables perhaps may seen a bit strange. So let us
briefly explain why this ordering is required. Firstly, in the Extended Path
we do not need to separately solve for control variables and lagged control
variables (i.e. $C_{t-1}$ and $C_{t}$ in our case). Instead, we exploits
that we only need to solve for the control variables once and this increases
the numerical efficiency of the codes. To exploit this numerical trick, the
codes require that the link equations appear after the main model equations
and that the state and control vectors are ordered as outlined in (\ref{1})
and (\ref{2}). Secondly, we also exploit that for linear shock processes, we
can easily solve for these variables in the Extended Path independently of
any of the endogenous variables in the model. This explains why the
exogenous shocks must appear last in the $\mathbf{f}$-function and the
exogenous shocks must appear last in the state vector. We should finally
note that the user may "turn off" both of these optimized features in the
codes by letting $mx=nx$ and $myx=0$. This may for instance be useful when
debugging the codes.

\bigskip

\subsection{Implementing the Steady State\label{SteadyState}}

Our implementation of the steady state solution for our RBC model is
available in "RBCmodel\_ss.m" appearing in the folder "ModelSpecification".
The first part of this function defines the output arguments as follows:%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7512in}{1.7658in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 1.7658in;depth 0pt;original-width 6.2745in;original-height 1.6223in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSFUH09.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.6223in, natwidth=6.2745in, height=1.7658in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSFUH09__9.pdf}}%
\end{center}
%EndExpansion
All output are stored in "auxOut" (auxiliary output) and "errorMes", which
is a flag for reporting errors. We then set the size of the model. 

\bigskip 

The next step is to unfold the structural parameters in the structure
"params". We also define the eta-matrix $\mathbf{\eta }$ which in our
framework is the square-root of the covariance matrix to the structural
shocks. Note that technology $A_{t}$ appears at the third position in $%
\mathbf{x}_{t}$, and $\sigma _{A}$ therefore appears at position $\eta
\left( 3,1\right) $ and so on. Finally, we set the higher order moments,
which we specify to be Gaussian (using the codes provided by \cite%
{Levintal_2017}). 
%TCIMACRO{%
%\FRAME{dtbpFX}{4.2338in}{3.1109in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 4.2338in;height 3.1109in;depth 0pt;original-width 6.2745in;original-height 4.6019in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSFYF0A.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=4.6019in, natwidth=6.2745in, height=3.1109in, width=4.2338in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSFYF0A__10.pdf}}%
\end{center}
%EndExpansion

\bigskip

The second section of "RBCmodel\_ss.m" reported on the next page simply
computes the steady state as a function of the structural parameters.

\newpage

%TCIMACRO{%
%\FRAME{dtbpFX}{5.6737in}{3.9703in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.6737in;height 3.9703in;depth 0pt;original-width 6.2745in;original-height 4.3806in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSG260B.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=4.3806in, natwidth=6.2745in, height=3.9703in, width=5.6737in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSG260B__11.pdf}}%
\end{center}
%EndExpansion
and%
%TCIMACRO{%
%\FRAME{dtbpFX}{5.6737in}{3.1174in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.6737in;height 3.1174in;depth 0pt;original-width 6.2745in;original-height 3.4336in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSG2Z0C.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=3.4336in, natwidth=6.2745in, height=3.1174in, width=5.6737in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSG2Z0C__12.pdf}}%
\end{center}
%EndExpansion

To find the steady state value of hours worked, i.e. $N_{ss}$, the function
"findN" is defined in the bottom of the file "RBCmodel\_ss.m" as follows%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7603in}{0.6614in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7603in;height 0.6614in;depth 0pt;original-width 6.3741in;original-height 0.5996in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'NO0UZX0B.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=0.5996in, natwidth=6.3741in, height=0.6614in, width=6.7603in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/NO0UZX0B__13.pdf}}%
\end{center}
%EndExpansion

\bigskip

The third section in "RBCmodel\_ss.m" simply assigns the steady state values
to all elements in the states (in "X$_{\text{ss}}$") and the controls (in "Y$%
_{\text{ss}}$") in the appropriate order. Then we also provide the name of
the variables in "labelx" and "labely", respectively. Finally, we indicate
in "transformX" and "transformY", which transformation that is applied for
each of the variables in the model. Note that we use a log-transformation of
the steady state because all variables in "RBCmodel.m" were transformed by
the exp-function.%
%TCIMACRO{%
%\FRAME{dtbpFX}{5.6737in}{2.2839in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.6737in;height 2.2839in;depth 0pt;original-width 6.2745in;original-height 2.5077in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSG630D.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=2.5077in, natwidth=6.2745in, height=2.2839in, width=5.6737in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSG630D__14.pdf}}%
\end{center}
%EndExpansion

Within the third section of "RBCmodel\_ss.m" we finally save some auxiliary
output in the structure. 

\bigskip

\subsection{Non-Standard Transformations in The Model\label{untransformXandY}%
}

In some cases it may also be necessary to "untransform" the solution from
the approximation to get the model output to match with the corresponding
output in the data. This should currently only be the case if a logistic
function is used, but it may also be the case for a log-transformation if
the empirical data is not log-transformed. In any case, it is recommended
that one briefly checks the content of the file "untransformYandX.m" which
currently reads:%
%TCIMACRO{%
%\FRAME{dtbpFX}{4.4195in}{3.8681in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 4.4195in;height 3.8681in;depth 0pt;original-width 6.2745in;original-height 5.4864in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQSGJI0E.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=5.4864in, natwidth=6.2745in, height=3.8681in, width=4.4195in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQSGJI0E__15.pdf}}%
\end{center}
%EndExpansion

\subsection{Generating Functions for the Numerical Derivatives\label%
{NumDerivatives}}

Based on the two model specific m-files, we are now able to generate
functions that compute the required numerical derivatives of the model.

To generate these functions for standard perturbation, open the executable
script called "createFiles\_Derivatives\_model.m". The user specific part of
this script is given below:%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7512in}{1.2924in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 1.2924in;depth 0pt;original-width 6.2745in;original-height 1.1797in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQTCW70M.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.1797in, natwidth=6.2745in, height=1.2924in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQTCW70M__16.pdf}}%
\end{center}
%EndExpansion
We first specify the order of the approximation using "orderApp". Then we
call the m-file containing the model equations - i.e. "RBCmodel.m" in our
case. Finally, we need to provide the name of the file computing the DSGE
model in the steady state. Here, the name of the file (i.e.\ RBCmodel\_ss)
is optional but the output arguments must be as indicated above. Based on
these inputs, running the script then uses the codes of \cite{Levintal_2017}
to compute the required derivatives.

\bigskip 

To generate the functions for the Extended Path (as needed for the extended
perturbation method) and to generate codes to compute the Euler equation
errors, open the executable script called
"createFiles\_ExtendedPathAndAccuracy.m". The user specific part of this
script is given below:%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7512in}{1.1335in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 1.1335in;depth 0pt;original-width 6.2745in;original-height 1.0329in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQTD470N.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.0329in, natwidth=6.2745in, height=1.1335in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQTD470N__17.pdf}}%
\end{center}
%EndExpansion
For the Extended Path, it is useful to express all the model equations (and
hence their errors) in unit free terms to make the errors comparable across
the various equations in the model. We account for this in the current
implementation by letting "unitFree = 1". Finally, we need to specify the
number of endogenous states "mx=1" and the number of lagged controls "myx =
1" in our case.

Following the construction of these files, we are now ready to carry out the
SMM estimation.

\bigskip

\subsection{Executing the SMM Estimation\label{runSMM}}

To start the SMM estimation, open the file called "RunSMM.m", which
simulates a sample path from our RBC\ model and then estimates the RBC\
model on this sample path. The first section of this file lists the main
user settings:%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7512in}{2.588in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 2.588in;depth 0pt;original-width 6.2745in;original-height 2.3893in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQTBT30F.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=2.3893in, natwidth=6.2745in, height=2.588in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQTBT30F__18.pdf}}%
\end{center}
%EndExpansion
That is, we select the approximation method ("appMethod") and the length of
the simulated sample path ("tau") used to compute the model implied moments.
We also set the order of the approximation ("orderApp"), and the length of
the sample path ("T"). Then we specify the number of moments which we can
select from in the estimation. Here

\begin{itemize}
\item "autoLagsIdx" specifies the considered lags for the own
auto-covariances of $\mathbf{y}_{t}$ which appear in the moment conditions.
In this case, we include $\left\{ y_{i,t}y_{i,t-1}\right\} _{i=1}^{n_{y}}$
and $\left\{ y_{i,t}y_{i,t-5}\right\} _{i=1}^{n_{y}}$ in $\mathbf{m}%
_{3}\left( \mathbf{y}_{t}\right) $

\item "selectY" selects the elements in the control vector which we consider
for the SMM estimation. In our case, we use position 1,2, and 5 in $\mathbf{y%
}_{t}$, implying that we use moments for\textbf{\ }$\left[ 
\begin{array}{ccc}
\log C_{t} & \log I_{t} & \log N_{t}%
\end{array}%
\right] $ in the estimation (see (\ref{3}))
\end{itemize}

Below in the "inclMoms\_Ey", etc. we then specify which of the moments among
the ones considered for the estimation that we really want to include. Here,
a 1 indicates that a moment is include, and zero otherwise. Finally, "qLag"
is the number of lags when computing the Newey-West estimate of the
weighting matrix, and "epsValue" is the step size used when computing
standard errors for the SMM estimator.

\bigskip 

The next part of the control settting relates to the optimizer%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7512in}{1.5923in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 1.5923in;depth 0pt;original-width 6.2745in;original-height 1.4602in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQTC150G.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.4602in, natwidth=6.2745in, height=1.5923in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQTC150G__19.pdf}}%
\end{center}
%EndExpansion

\begin{itemize}
\item "optim" = 1 for the CMAES routine considered in \cite%
{Andreasen_2010opt}

\item "optim" = 2 for the Levenberg-Marquard algorithm in Matlab as the
objective function in the SMM estimation can be expressed as%
\begin{eqnarray*}
Q &=&\mathbf{g}^{S}\left( \mathbf{\theta ,y}_{1:T}\right) ^{\prime }\mathbf{W%
}_{T}\mathbf{g}^{S}\left( \mathbf{\theta ,y}_{1:T}\right) \\
&=&\mathbf{g}^{S}\left( \mathbf{\theta ,y}_{1:T}\right) ^{\prime }\mathbf{S}%
_{T}^{\prime }\mathbf{S}_{T}\mathbf{g}^{S}\left( \mathbf{\theta ,y}%
_{1:T}\right) \\
&=&\left( \mathbf{S}_{T}\mathbf{g}^{S}\left( \mathbf{\theta ,y}_{1:T}\right)
\right) ^{\prime }\left( \mathbf{S}_{T}\mathbf{g}^{S}\left( \mathbf{\theta ,y%
}_{1:T}\right) \right) \\
&=&\mathbf{\tilde{g}}\left( \mathbf{\theta ,y}_{1:T}\right) ^{\prime }%
\mathbf{\tilde{g}}\left( \mathbf{\theta ,y}_{1:T}\right)
\end{eqnarray*}%
where $\mathbf{W}_{T}=\mathbf{S}_{T}^{\prime }\mathbf{S}_{T}$ is the
Cholesky decomposition. Hence, the structure of the SMM estimator is
equivalent to a non-linear least squares regression problem for which the
Levenberg-Marquard algorithm applies.

\item "optim" =\ 3 for the Nelder-Mead simplex algorithm

\item "numOptimStep1" and "numOptimStep2" is the number of times we restart
the optimizer in step 1 and step 2, respectively.

\item The following five options specified in section 1 of "RunSMM.m" relate
to the optimizers and should be obvious. 
\end{itemize}

\bigskip 

For extended perturbation, there is an additional set of options which the
user needs to set. Let us briefly go through these options and explain how
they are related to \cite{AndreasenKronborg_2018}. These options are stored
in the struct setupEPer as follows:%
%TCIMACRO{%
%\FRAME{ftbpFX}{6.7512in}{2.8101in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 2.8101in;depth 0pt;original-width 6.2745in;original-height 2.5961in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQTCCF0H.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{figure}[ptb]\begin{center}
\fbox{\includegraphics[
natheight=2.5961in, natwidth=6.2745in, height=2.8101in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQTCCF0H__20.pdf}}%
\end{center}\end{figure}%
%EndExpansion

\begin{itemize}
\item "Nmax" denotes the maximal horizon for the Extended Path and is
denoted by $N_{\max }$ in \cite{AndreasenKronborg_2018}.

\item "Nmin" denotes the shortest allowed horizon for the Extended Path and
is denoted by $N_{\min }$ in \cite{AndreasenKronborg_2018}.

\item "maxDistSS" is the maximal allowed distance to the steady state, which
is allowed when setting the horizon $N$ in the Extended Path. Hence,
"maxDistSS" corresponds to "$D_{ss}$" in \cite{AndreasenKronborg_2018}.

\item "orderAppStart" is the approximation order used in standard
perturbation to obtain good starting values for the Extended Path.

\item "fixedPointSolver" determines which fixed-point solver is used in the
Extended Path. The two first options are standard fixed-point algorithms,
whereas the latter two simply minimizes the euler-equation errors by a type
of Levenberg-Marquard (LM) algorithm. When "fixedPointSolver=4", then we put
decaying weights on euler equation errors from period "t" and until period
"t+N". Note also if these algorithms are unable to solve for the certainty
equivalence solution, then we restart the Extended Path using a "backup" LM
algorithm.

\item "JacobianOption" specifies how we solve a linear equation system
within each iteration of the Newton-Rapson solver, i.e. when
"fixedPointSolver = 1" or "fixedPointSolver = 2". Here, "JacobianOption = 2"
uses analytical derivatives of the model to formulate this linear problem,
which is solved by standard methods (although exploiting the sparcity of the
system). When "JacobianOption = 3", then we recursively solve this linear
system as outlined in \cite{boucekkine:95}. Normally, the fastest option is
to let "JacobianOption = 3", whereas "JacobianOption = 1" is only for
debugging.

\item "lambda0" and "lambdaBackup" are tuning coefficients for the LM
algorithm.

\item "tolf" is the tolerance used when solving for the Extended Path.

\item "MaxIter" is the max number of iterations allowed for when solving for
the Extended Path.

\item "ResidualMax" is "$EE$" in \cite{AndreasenKronborg_2018}.

\item "MexOn" allows you to use an Mex implementation of
"CondMoments\_4th\_levelCE.m". BUT, here you probably need to recompile the
Mex-file unless you can use my compiled version (applies to 64bit computer
windows machine)
\end{itemize}

\bigskip

In the second section of "RunSMM.m" the user first needs to list in
"allModelParams" all the names of the structural parameters appearing in the
DSGE model. We use this list of coefficients to check that a given
structural coefficient is either calibrated or estimated.%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7512in}{3.0306in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7512in;height 3.0306in;depth 0pt;original-width 6.2745in;original-height 2.8028in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQTCEC0I.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=2.8028in, natwidth=6.2745in, height=3.0306in, width=6.7512in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQTCEC0I__21.pdf}}%
\end{center}
%EndExpansion
In the structure "calibrateParams", we denote the parameters which are
calibrated and their calibrated values. In the structure "params0", we
denote the parameters which are estimated and their starting value for the
SMM estimation.

\bigskip

Section 3 of "RunSMM.m" reads:%
%TCIMACRO{%
%\FRAME{dtbpFX}{5.047in}{6.2931in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.047in;height 6.2931in;depth 0pt;original-width 6.2745in;original-height 7.832in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQTCGD0J.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=7.832in, natwidth=6.2745in, height=6.2931in, width=5.047in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQTCGD0J__22.pdf}}%
\end{center}
%EndExpansion
That is, we load our empirical data, which in our case is a simulated sample
path. Then we compute the chosen moments on the empirical data and test if
we have sufficient moments for the estimation. We finally set the search
distribution in the CMAES routine ("Insigma") and the lower and upper bounds
for all parameters in the model.

\bigskip

In section 4 of "Run\_SMM.m", we simply save all relevant information for
the SMM estimation in the structure "setupStep1".%
%TCIMACRO{%
%\FRAME{dtbpFX}{5.6737in}{3.2139in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 5.6737in;height 3.2139in;depth 0pt;original-width 6.2745in;original-height 3.5398in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'PQTCI50K.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=3.5398in, natwidth=6.2745in, height=3.2139in, width=5.6737in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/PQTCI50K__23.pdf}}%
\end{center}
%EndExpansion

\bigskip

The first step of the SMM estimation is carried out in section 5 of
"RunSMM.m":%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7602in}{1.0404in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7602in;height 1.0404in;depth 0pt;original-width 6.3741in;original-height 0.9587in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'OGS5W70A.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=0.9587in, natwidth=6.3741in, height=1.0404in, width=6.7602in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/OGS5W70A__24.pdf}}%
\end{center}
%EndExpansion
We start by computing the weighting matrix using the value of the moments in
the empirical sample, that is we compute $\mathbf{W}_{T}=\left( \mathbf{\hat{%
S}}_{mean}\right) ^{-1}$ using the notation introduced in Section \ref%
{SMMestimation}. Then we use the diagonal of $\mathbf{W}_{T}$ and save its
square-root in "setupStep1.Sw". We then run the first step of the SMM
estimation and compute standard errors. All results from the first
estimation step are available in the structure "resultsStep1" which takes
the following form:%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.9937in}{1.6743in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.9937in;height 1.6743in;depth 0pt;original-width 6.5956in;original-height 1.5583in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'OGS66U0B.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.5583in, natwidth=6.5956in, height=1.6743in, width=6.9937in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/OGS66U0B__25.pdf}}%
\end{center}
%EndExpansion
That is, we report the estimated parameters ("params"), the standard errors
("paramsSE"), the jacobian to test for local identification ("Jacobian"),
the value of the objective function at optimum ("Q"), the perturbation
approximation in the structure "model", the moments in the RBC model
("modelMoments"), the moments in the empirical sample ("dataMoments"), and
the type of the i'th moments considered in "nameMoments". Finally, we also
report the scaled version of these moments.

\bigskip

The second step of the SMM estimation is carried out in section 6 of
"RunSMM.m":%
%TCIMACRO{%
%\FRAME{dtbpFX}{6.7602in}{1.9268in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.7602in;height 1.9268in;depth 0pt;original-width 6.3741in;original-height 1.798in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'OGS6990C.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.798in, natwidth=6.3741in, height=1.9268in, width=6.7602in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/OGS6990C__26.pdf}}%
\end{center}
%EndExpansion
We start by getting the model moments from the first step and use these
moments to compute the optimal weighting matrix ("Wopt"). Then we run the
second estimation step and obtain standard errors. All results from the
second estimation step are available in the structure "resultsStep2" which
has the following form: 
%TCIMACRO{%
%\FRAME{dtbpFX}{6.9937in}{2.0531in}{0pt}{}{}{Figure}{%
%\special{language "Scientific Word";type "GRAPHIC";maintain-aspect-ratio TRUE;display "USEDEF";valid_file "T";width 6.9937in;height 2.0531in;depth 0pt;original-width 6.5956in;original-height 1.9182in;cropleft "0";croptop "1";cropright "1";cropbottom "0";tempfilename 'OGS6AR0D.wmf';tempfile-properties "XPR";}}}%
%BeginExpansion
\begin{center}
\fbox{\includegraphics[
natheight=1.9182in, natwidth=6.5956in, height=2.0531in, width=6.9937in]
{U:/Teaching/PhDMacro_DSGEmodels/Estimation/SMM_ExtendedPerLagY_5th_v1/Documentation/graphicsMMA/OGS6AR0D__27.pdf}}%
\end{center}
%EndExpansion
Compared to resultsStep1, the only new items are the reported test statistic
for the J-test ("Jtest"), the number of degrees of freedom for the J-test
("JtestDf"), and the related P-value ("ProbJtest").

\subsection{Evaluating Accuracy\label{accuracy}}

The script "Run\_accuracyEuler.m" allows you to evaluate the accuracy of the
approximation by computing the Euler equation errors along a simulated
sample path or an a grid. When computing the Euler equation errors,
Gauss-Hermite polynomials are used to carry out the numerical integration
impled by the conditional expectation operator. 

\bigskip 

\bibliographystyle{agsm}
\bibliography{ExtendedPer_bib,REF}

\end{document}
